package com.hzhr.iot.device.service;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.CygQuery;
import com.hzhr.iot.core.annotation.CygQuerys;
import com.hzhr.iot.core.annotation.CygService;
import com.hzhr.iot.core.constant.AccessModeEnum;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.constant.DeviceOptions;
import com.hzhr.iot.device.constant.DeviceOptionsName;
import com.hzhr.iot.device.constant.DeviceOptionsTypeName;
import com.hzhr.iot.device.constant.Device_ErrorsEnum;
import com.hzhr.iot.device.convertor.DeviceInfoCardConvertor;
import com.hzhr.iot.device.convertor.custom.DeviceInfoCardCustomConvertor;
import com.hzhr.iot.device.dao.DeviceInfoCardDao;
import com.hzhr.iot.device.entity.DeviceInfoCardEntity;
import com.hzhr.iot.device.entity.ext.DeviceInfoCardEntityExt;
import com.hzhr.iot.device.model.regulatorDevice_infoCard.RegulatorDevice_InfoCardGetModel;
import com.hzhr.iot.device.model.regulatorDevice_infoCard.RegulatorDevice_InfoCardModel;
import com.hzhr.iot.device.model.regulatorDevice_infoCard.RegulatorDevice_InfoCardPutModel;
import com.hzhr.iot.device.queryModel.custom.DeviceInfoCardCustomQueryModel;
import com.hzhr.iot.device.service.base.BaseService;
import com.hzhr.iot.login.sdk.model.userCard.UserCardModel;
import com.hzhr.iot.user.sdk.model.dept.DeptGetModel;
import com.hzhr.iot.user.sdk.model.dept.DeptModel;
import com.hzhr.iot.user.sdk.service.User_DeptService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@CygService(entity = DeviceInfoCardEntity.class, model = RegulatorDevice_InfoCardModel.class)
@CygQuerys({
        @CygQuery(name = "_equal_id", query = "equal_id", type = Integer.class),

})
public class RegulatorDevice_InfoCardService extends BaseService {
    @Autowired
    DeviceInfoCardDao deviceInfoCardDao;

    @Autowired
    DeviceOptions deviceOptions;

    @Autowired
    DeviceInfoCardCustomConvertor deviceInfoCardCustomConvertor;

    @Autowired
    DeviceInfoCardConvertor deviceInfoCardConvertor;

    @Autowired
    User_DeptService user_deptService;

    @Autowired
    RegulatorDevice_InfoCardService regulatorDevice_infoCardService;


    //region javadoc注释 : putByRegulatorDeviceIdAndId
    /**
     * 根据调压设备编号和信息卡片编号编辑调压设备下的信息卡片 <br/><br/>
     * 简介 : 根据调压设备编号和信息卡片编号编辑调压设备下的信息卡片 <br/>
     * 步骤 : <br/>
     * 1. 查询信息卡片 : <br/>
     *  根据路径参数regulatorDeviceId和id查询信息卡片(DEVICE_INFO_CARD)deviceInfoCard_1， <br/>
     *  路径参数筛选规则如下： <br/>
     *  (1) deviceInfoCard_1.id = 路径参数id； <br/>
     *  (2) deviceInfoCard_1.deviceExt.id = 路径参数regulatorDeviceId； <br/>
     *  额外筛选规则如下： <br/>
     *  (1) deviceInfoCard_1.deviceExt.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK； <br/>
     *  如果deviceInfoCard_1不存在，抛出异常201； <br/>
     * 2. 修改信息卡片 : <br/>
     *  根据body修改deviceInfoCard_1的相关信息； <br/>
     * 3. 返回信息 : <br/>
     *  根据条件参数查询修改后的deviceInfoCard_1的信息生成结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_device : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示设备信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param regulatorDeviceId 调压设备编号 <br/><br/>
     * @param id 信息卡编号 <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * REGULATORDEVICE_INFOCARDSERVICE_PUT_BY_REGULATOR_DEVICE_ID_AND_ID_201 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 查询信息卡片<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 信息卡片不存在<br/>
     * @see RegulatorDevice_InfoCardPutModel body <br/>
     * @see RegulatorDevice_InfoCardGetModel result <br/>
     */ 
    //endregion
    //region 说明 : putByRegulatorDeviceIdAndId
    //根据调压设备编号和信息卡片编号编辑调压设备下的信息卡片
    //简介 : 根据调压设备编号和信息卡片编号编辑调压设备下的信息卡片
    //步骤 :
    //1. 查询信息卡片 :
    // 根据路径参数regulatorDeviceId和id查询信息卡片(DEVICE_INFO_CARD)deviceInfoCard_1，
    // 路径参数筛选规则如下：
    // (1) deviceInfoCard_1.id = 路径参数id；
    // (2) deviceInfoCard_1.deviceExt.id = 路径参数regulatorDeviceId；
    // 额外筛选规则如下：
    // (1) deviceInfoCard_1.deviceExt.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK；
    // 如果deviceInfoCard_1不存在，抛出异常201；
    //2. 修改信息卡片 :
    // 根据body修改deviceInfoCard_1的相关信息；
    //3. 返回信息 :
    // 根据条件参数查询修改后的deviceInfoCard_1的信息生成结果对象并返回；
    //endregion
    //region 参数 : putByRegulatorDeviceIdAndId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "regulatorDeviceId", value = "调压设备编号",required = true, dataType = "int", paramType = "path"),
            @ApiImplicitParam(name = "id", value = "信息卡编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_device", value = "是否展示设备信息", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_device", value = "是否展示设备信息", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : putByRegulatorDeviceIdAndId
    @RequestMapping(value = "/regulator-devices/{regulatorDeviceId}/info-cards/{id}", method = RequestMethod.PUT)
    //endregion
    public RegulatorDevice_InfoCardGetModel putByRegulatorDeviceIdAndId(Map<String, String> header, Integer regulatorDeviceId,
                                                                        Integer id, Map<String, Object> query,
                                                                        RegulatorDevice_InfoCardPutModel body) throws ServiceException {
        /*查询信息卡片 */
        UserCardModel userCard = getUserCard(header);
        DeviceInfoCardCustomQueryModel queryModel = new DeviceInfoCardCustomQueryModel();
        queryModel.setEqual_id(id);
        queryModel.setEqual_deviceExt_id(regulatorDeviceId);
        String categoryCode = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY, DeviceOptionsName.COLLECT_DEVICE_CATEGORY.REGULATOR_BOX);
        String categoryCode1 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY, DeviceOptionsName.COLLECT_DEVICE_CATEGORY.USER_REGULATOR_TANK);
        String categoryCode2 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY, DeviceOptionsName.COLLECT_DEVICE_CATEGORY.SOURCE_REGULATOR_TANK);
        queryModel.setCategoryCode(categoryCode);
        queryModel.setCategoryCode1(categoryCode1);
        queryModel.setCategoryCode2(categoryCode2);
        queryModel.setShow(true);

        //selectExtList1
        DeviceInfoCardEntity deviceInfoCard_1 = deviceInfoCardDao.selectEntity1(queryModel);
        if (deviceInfoCard_1 == null){
            throw new ServiceException(Device_ErrorsEnum.REGULATORDEVICE_MAINTENANCECARDSERVICE_POST_BY_REGULATOR_DEVICE_ID_201);
        }

         /* 修改信息卡片*/
        deviceInfoCard_1.setRuningPressure(body.getRuningPressure());
        deviceInfoCard_1.setMainClosePressure(body.getMainClosePressure());
        deviceInfoCard_1.setSecondClosePressure(body.getSecondClosePressure());
        deviceInfoCard_1.setOffPressure(body.getOffPressure());
        deviceInfoCard_1.setEscapePressure(body.getEscapePressure());
        deviceInfoCard_1.setSafetyDevice(body.getSafetyDevice());
        deviceInfoCard_1.setPegCount(body.getPegCount());
        deviceInfoCard_1.setResidentCustomerCount(body.getResidentCustomerCount());
        deviceInfoCard_1.setResidentCustomerCount(body.getResidentCustomerCount());
        deviceInfoCard_1.setCommercialCustomerCount(body.getCommercialCustomerCount());
        deviceInfoCard_1.setCollectiveCustomerCount(body.getCollectiveCustomerCount());
        deviceInfoCard_1.setIndustrialCustomerCount(body.getIndustrialCustomerCount());
        deviceInfoCard_1.setOtherCustomerCount(body.getOtherCustomerCount());
        deviceInfoCard_1.setCreateTime(new Date());
        deviceInfoCard_1.setUpdateUserId(userCard.getUserId());
        int changeCount = deviceInfoCardDao.update(deviceInfoCard_1);
        int Total = deviceInfoCardDao.selectCount(queryModel);

        //3. 返回信息 :
        // 根据条件参数查询修改后的deviceInfoCard_1的信息生成结果对象并返回；
        RegulatorDevice_InfoCardGetModel result = regulatorDevice_infoCardService.get(initHeader(header,AccessModeEnum.GLOBAL),deviceInfoCard_1.getDeviceId(),query);
        result.setChangeCount(changeCount);
        result.setTotal(Total);
        return result;
    }

    //region javadoc注释 : get
    /**
     * 根据调压设备编号查询该调压设备的信息卡片 <br/><br/>
     * 简介 : 根据调压设备编号查询该调压设备的信息卡片 <br/>
     * 步骤 : <br/>
     * 1. 查询信息卡片 : <br/>
     *  根据条件参数和路径参数regulatorDeviceId查询信息卡片(DEVICE_INFO_CARD)deviceInfoCard_1， <br/>
     *  路径参数筛选规则如下： <br/>
     *  (1) deviceInfoCard_1.deviceId = 路径参数regulatorDeviceId； <br/>
     *  额外筛选规则如下： <br/>
     *  (1) deviceInfoCard_1.deviceExt.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK； <br/>
     * 2. 返回信息 : <br/>
     *  根据deviceInfoCard_1及条件参数生成结果对象result并返回， <br/>
     *  其中DeviceInfoCardModel模型的managementName、subCompanyName属性的设置方法如下： <br/>
     *  使用GLOBAL方式调用deptService.get服务获取DeptModel模型进行相关设置，DeviceInfoCardModel模型与DeptModel模型的对应关系如下： <br/>
     *  (1) DeviceInfoCardModel模型的deptId属性对应于DeptModel模型的id属性(一对一)； <br/>
     *  (2) DeviceInfoCardModel模型的managementName属性对应于DeptModel模型的managementName属性； <br/>
     *  (3) DeviceInfoCardModel模型的subCompanyName属性对应于DeptModel模型的subCompanyName属性； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_device : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示设备信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where regulatorDevice_infoCard.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param regulatorDeviceId 调压设备编号 <br/><br/>
     * @throws ServiceException <br/>
     * @see RegulatorDevice_InfoCardGetModel result <br/>
     */ 
    //endregion
    //region 说明 : get
    //根据调压设备编号查询该调压设备的信息卡片
    //简介 : 根据调压设备编号查询该调压设备的信息卡片
    //步骤 :
    //1. 查询信息卡片 :
    // 根据条件参数和路径参数regulatorDeviceId查询信息卡片(DEVICE_INFO_CARD)deviceInfoCard_1，
    // 路径参数筛选规则如下：
    // (1) deviceInfoCard_1.deviceId = 路径参数regulatorDeviceId；
    // 额外筛选规则如下：
    // (1) deviceInfoCard_1.deviceExt.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK；
    //2. 返回信息 :
    // 根据deviceInfoCard_1及条件参数生成结果对象result并返回，
    // 其中DeviceInfoCardModel模型的managementName、subCompanyName属性的设置方法如下：
    // 使用GLOBAL方式调用deptService.get服务获取DeptModel模型进行相关设置，DeviceInfoCardModel模型与DeptModel模型的对应关系如下：
    // (1) DeviceInfoCardModel模型的deptId属性对应于DeptModel模型的id属性(一对一)；
    // (2) DeviceInfoCardModel模型的managementName属性对应于DeptModel模型的managementName属性；
    // (3) DeviceInfoCardModel模型的subCompanyName属性对应于DeptModel模型的subCompanyName属性；
    //endregion
    //region 参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "regulatorDeviceId", value = "调压设备编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_device", value = "是否展示设备信息", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where regulatorDevice_infoCard.id = #{equal_id}",required = false, dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_device", value = "是否展示设备信息", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where regulatorDevice_infoCard.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),

    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/regulator-devices/{regulatorDeviceId}/info-cards", method = RequestMethod.GET)
    //endregion
    public RegulatorDevice_InfoCardGetModel get(Map<String, String> header, Integer regulatorDeviceId,
                                                    Map<String, Object> query) throws ServiceException {
        // 1. 查询信息卡片 :
        // 根据条件参数和路径参数regulatorDeviceId查询信息卡片(DEVICE_INFO_CARD)deviceInfoCard_1，
        // 路径参数筛选规则如下：
        // (1) deviceInfoCard_1.deviceId = 路径参数regulatorDeviceId；
        // 额外筛选规则如下：
        // (1) deviceInfoCard_1.deviceExt.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK；
//             deviceInfoCard_1.deviceExt.categoryCode = REGULATOR_BOX or USER_REGULATOR_TANK or SOURCE_REGULATOR_TANK；
//        DeviceInfoCardCustomQueryModel queryModel = new DeviceInfoCardCustomQueryModel();
        DeviceInfoCardCustomQueryModel queryModel = deviceInfoCardCustomConvertor.regulatorDevice_InfoCardService_query2queryModel(query);
        queryModel.setEqual_deviceId(regulatorDeviceId);
        String categoryCode = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY,DeviceOptionsName.COLLECT_DEVICE_CATEGORY.REGULATOR_BOX);
        String categoryCode1 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY,DeviceOptionsName.COLLECT_DEVICE_CATEGORY.USER_REGULATOR_TANK);
        String categoryCode2 = deviceOptions.getCode(DeviceOptionsTypeName.COLLECT_DEVICE_CATEGORY,DeviceOptionsName.COLLECT_DEVICE_CATEGORY.SOURCE_REGULATOR_TANK);
        queryModel.setCategoryCode(categoryCode);
        queryModel.setCategoryCode1(categoryCode1);
        queryModel.setCategoryCode2(categoryCode2);
        queryModel.setShow(true);
        if (categoryCode != null && categoryCode1 != null &&  categoryCode2 != null){
            queryModel.setExt_deviceExt(true);
        }

        List<DeviceInfoCardEntityExt> list = deviceInfoCardDao.selectExtList1(queryModel);

        // 2. 返回信息 :
        // 根据deviceInfoCard_1及条件参数生成结果对象result并返回，
        // 其中DeviceInfoCardModel模型的managementName、subCompanyName属性的设置方法如下：
        // 使用GLOBAL方式调用deptService.get服务获取DeptModel模型进行相关设置，DeviceInfoCardModel模型与DeptModel模型的对应关系如下：
        // (1) DeviceInfoCardModel模型的deptId属性对应于DeptModel模型的id属性(一对一)；
        // (2) DeviceInfoCardModel模型的managementName属性对应于DeptModel模型的managementName属性；
        // (3) DeviceInfoCardModel模型的subCompanyName属性对应于DeptModel模型的subCompanyName属性；
        RegulatorDevice_InfoCardGetModel result = deviceInfoCardCustomConvertor.extList2regulatorDevice_InfoCardGetModel(list, null, null, query);
        RegulatorDevice_InfoCardModel model = result.getModel();
        if (model != null) {
            Integer deptId = model.getDeptId();
            if (deptId != null) {
                Map<String, Object> query1 = new HashMap<>();
                query1.put("_show", "one");
                query1.put("_equal_id", deptId);
                query1.put("_show_managementName", true);
                query1.put("_show_subCompanyName", true);
                DeptGetModel deptGetModel = user_deptService.get(initHeader(header, AccessModeEnum.GLOBAL), query1);
                DeptModel dept = deptGetModel.getModel();
                if (dept != null){
                    model.setManagementName(dept.getManagementName());
                    model.setSubCompanyName(dept.getSubCompanyName());
                }
            }
        }

        List<RegulatorDevice_InfoCardModel> modelList = result.getModelList(); // List
        if (modelList != null) {
            for (RegulatorDevice_InfoCardModel model1 : modelList){
                Integer deptId = model1.getDeptId();
                if (deptId != null) {
                    //因为此处List只会是一个对象，故采取此方法；
                    Map<String, Object> query1 = new HashMap<>();
                    query1.put("_show", "list");
                    query1.put("_equal_id", deptId);
                    query1.put("_show_managementName", true);
                    query1.put("_show_subCompanyName", true);
                    DeptGetModel deptGetModel = user_deptService.get(initHeader(header, AccessModeEnum.GLOBAL), query1);
                    List<DeptModel> depts = deptGetModel.getModelList();
                    for (DeptModel deptModel : depts){
                        if (deptModel.getId()== deptId){
                            deptModel.setManagementName(model1.getManagementName());
                            deptModel.setSubCompanyName(model1.getSubCompanyName());
                        }

                    }
                }
            }
        }
        return result;
    }
}

